<?php

/*
 * This is to move hospital file to personal folder.
 */
include '../../include/config.php';
$file_name = $_POST['file'];
$document = $_POST['document'];
$folder_id = $_POST['folder_id'];
$hos_file_id = $_POST['hos_file_id'];
$fol1 = mysql_query("select * from me_folders where sr= $folder_id ") or die(mysql_error());
while ($row = mysql_fetch_array($fol1)) {
    $folder_name  = $row['folder'];
}


/*
 * default path for user of Me.
 */
$target_path = '/var/www/html/salusme/storage/'.$_COOKIE['vid'].'/folders/'.$folder_name.'/';
//$target_path = '/home/salusban/www/salusbank.ch/salusme/storage/'.$_COOKIE['vid'].'/folders/'.$folder_name.'/';
/*
 * default path of salushospital storage.
 */
$hos_file_path = '/var/www/html/salushospital/storage/'.$document;
//$hos_file_path = '/home/salusban/www/salusbank.ch/salushospital/storage/'.$document;

/*
 * main logic
 */
$date = date('Y-m-d');
$uid = $_COOKIE['vid'];

if (!copy($hos_file_path, $target_path.$document)) {
    echo "failed to copy...\n";
}else{
   /*
    * update in hospital_data
    */
   mysql_query("update hospital_data set flag = 1 where sr = $hos_file_id") or die(mysql_error());
   /*
    * inserting into me_upload_files
    */
   mysql_query("insert into me_upload_files (sr,file_name,uid,mdir,attr,date) values(NULL,'$document',$uid,'$folder_name','$file_name',$date) ") or die(mysql_error());   
   header('Location:../view/inbox');
}
   


?>
